import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:snail_player/app/pages/settings/widgets/permission_item.dart';

import '../data_utils.dart';
import 'PermissionsController.dart';

class PermissionsList extends StatelessWidget {

  final PermissionsController controller = Get.put(PermissionsController());


  // todo 备注，将此类，的item 改为 通过入参传入 item list ，动态传入，这样可以在外部手动创建 item 以及 item 的事件功能

  @override
  Widget build(BuildContext context) {
    final permissions = DataUtils.getPermissionsData();

    bool boolValue = true;

    return SingleChildScrollView(
      child: Column(
        children: [
          Container(
            width: 358,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(18),
              boxShadow: [
                BoxShadow(
                  color: Color(0x195c54ff),
                  blurRadius: 30,
                  offset: Offset(0, 10),
                ),
              ],
              color: Colors.white,
            ),
            padding: const EdgeInsets.only(top: 16, bottom: 8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min, // 保证高度自适应
              children: [
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 24),
                  child: const Text(
                    "权限设置",
                    style: TextStyle(
                      color: Color(0xff99a1aa),
                      fontSize: 15,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
                SizedBox(height: 16),
                // 使用ListView.builder渲染PermissionItem列表
                ListView.builder(
                  shrinkWrap: true, // 高度根据内容自适应
                  physics: NeverScrollableScrollPhysics(), // 让ListView的滚动与主页面保持一致
                  itemCount: permissions.length,
                  itemBuilder: (context, index) {
                    return Column(
                      children: [
                        PermissionItem(
                          title: permissions[index]['title'],
                          icon: permissions[index]['icon'],
                          value: boolValue, // 初始布尔值
                          onBoolChange: (value) {
                            // boolValue = value;
                          },

                        ),
                        if (index != permissions.length - 1) SizedBox(height: 8), // 非最后一项的间距
                      ],
                    );
                  },
                ),
              ],
            ),
          ),
          SizedBox(height: 16),
          Container(
            width: 358,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(18),
              boxShadow: [
                BoxShadow(
                  color: Color(0x195c54ff),
                  blurRadius: 30,
                  offset: Offset(0, 10),
                ),
              ],
              color: Colors.white,
            ),
            padding: const EdgeInsets.only(top: 16, bottom: 8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min, // 保证高度自适应
              children: [
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 24),
                  child: const Text(
                    "权限设置",
                    style: TextStyle(
                      color: Color(0xff99a1aa),
                      fontSize: 15,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
                SizedBox(height: 16),
                // 使用ListView.builder渲染PermissionItem列表
                ListView.builder(
                  shrinkWrap: true, // 高度根据内容自适应
                  physics: NeverScrollableScrollPhysics(), // 让ListView的滚动与主页面保持一致
                  itemCount: permissions.length,
                  itemBuilder: (context, index) {
                    return Column(
                      children: [
                        PermissionItem(
                          title: permissions[index]['title'],
                          icon: permissions[index]['icon'],
                        ),
                        if (index != permissions.length - 1) SizedBox(height: 8), // 非最后一项的间距
                      ],
                    );
                  },
                ),
              ],
            ),
          ),
          SizedBox(height: 16),
          Container(
            width: 358,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(18),
              boxShadow: [
                BoxShadow(
                  color: Color(0x195c54ff),
                  blurRadius: 30,
                  offset: Offset(0, 10),
                ),
              ],
              color: Colors.white,
            ),
            padding: const EdgeInsets.only(top: 16, bottom: 8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min, // 保证高度自适应
              children: [
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 24),
                  child: const Text(
                    "权限设置",
                    style: TextStyle(
                      color: Color(0xff99a1aa),
                      fontSize: 15,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
                SizedBox(height: 16),
                // 使用ListView.builder渲染PermissionItem列表
                ListView.builder(
                  shrinkWrap: true, // 高度根据内容自适应
                  physics: NeverScrollableScrollPhysics(), // 让ListView的滚动与主页面保持一致
                  itemCount: permissions.length,
                  itemBuilder: (context, index) {
                    return Column(
                      children: [
                        PermissionItem(
                          title: permissions[index]['title'],
                          icon: permissions[index]['icon'],
                        ),
                        if (index != permissions.length - 1) SizedBox(height: 8), // 非最后一项的间距
                      ],
                    );
                  },
                ),
              ],
            ),
          ),
          SizedBox(height: 16),
          Container(
            width: 358,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(18),
              boxShadow: [
                BoxShadow(
                  color: Color(0x195c54ff),
                  blurRadius: 30,
                  offset: Offset(0, 10),
                ),
              ],
              color: Colors.white,
            ),
            padding: const EdgeInsets.only(top: 16, bottom: 8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min, // 保证高度自适应
              children: [
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 24),
                  child: const Text(
                    "权限设置",
                    style: TextStyle(
                      color: Color(0xff99a1aa),
                      fontSize: 15,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
                SizedBox(height: 16),
                // 使用ListView.builder渲染PermissionItem列表
                ListView.builder(
                  shrinkWrap: true, // 高度根据内容自适应
                  physics: NeverScrollableScrollPhysics(), // 让ListView的滚动与主页面保持一致
                  itemCount: permissions.length,
                  itemBuilder: (context, index) {
                    return Column(
                      children: [
                        PermissionItem(
                          title: permissions[index]['title'],
                          icon: permissions[index]['icon'],
                        ),
                        if (index != permissions.length - 1) SizedBox(height: 8), // 非最后一项的间距
                      ],
                    );
                  },
                ),
              ],
            ),
          ),
          SizedBox(height: 16),
        ],
      ),
    );
  }

  void changeValue(bool value) {

  }

}
